/**
 * Created by 鹏 on 14-3-10.
 */
var routes = require('./routes');
var filters = require('./routes/filters');
var install = require('./routes/install');
var user = require('./routes/user');
var project = require('./routes/project');
var team = require('./routes/team');
var task = require('./routes/task');

var installService = require('./service/installService');
var db = require("./common/db");

exports.start = function (app) {
    var config = installService.getConfig();
    app.set("SysConfig", config);
    if (config.Install) {
        //创建数据库连接池
        db.createConnectionPool(config);
    }

    app.get('/', filters.installFilter, routes.signIn);
    app.get('/Install', filters.installFilter, install.index);
    app.post('/RunInstall', filters.installFilter, install.install);
    app.get('/Installed', filters.installFilter, install.installed);

    app.post('/User/Verify', filters.installFilter, user.verify);
    app.get('/SignUp', filters.installFilter, user.signUp);
    app.get('/SignOut', filters.installFilter, filters.signInFilter, routes.signOut);
    app.post('/User/Create', filters.installFilter, user.create);

    app.get('/Desktop', filters.installFilter, filters.signInFilter, project.desktop);
    app.post('/Project/Create', filters.installFilter, filters.signInFilter, project.create);
    app.get('/Project/Dashboard/:ProjectId', filters.installFilter, filters.signInFilter, project.dashboard);

    app.get('/Team/:ProjectId', filters.installFilter, filters.signInFilter, team.member);
    app.post('/Team/InProject', filters.installFilter, filters.signInFilter, team.memberInProject);
    app.post('/Team/Candidate', filters.installFilter, filters.signInFilter, team.memberCandidate);
    app.post('/Team/AddMember', filters.installFilter, filters.signInFilter, team.addMember);
    app.post('/Team/RemoveMember', filters.installFilter, filters.signInFilter, team.removeMember);

    app.get('/Task/:ProjectId', filters.installFilter, filters.signInFilter, task.list);
    app.post('/Task/GetTags', filters.installFilter, filters.signInFilter, task.getTags);
    app.post('/Task/Create', filters.installFilter, filters.signInFilter, task.create);
    app.post('/Task/Query', filters.installFilter, filters.signInFilter, task.query);
    app.get('/Task/Detail/:ProjectId/:TaskId', filters.installFilter, filters.signInFilter, task.detail);
    app.post('/Task/Update', filters.installFilter, filters.signInFilter, task.update);
    app.post('/Task/Get', filters.installFilter, filters.signInFilter, task.get);
};